package com.guw.TestThread;

//线程优先级,范围从1-10,
//改变优先级的方式:getPriority(),setPriority(int x);
//优先级高未必先执行
public class TestPriority implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"的优先级是"+Thread.currentThread().getPriority());
    }
    public static void main(String[] args) {
        TestPriority testPriority = new TestPriority();
        Thread t1 = new Thread(testPriority,"A");
        Thread t2 = new Thread(testPriority,"B");
        //设置优先级再启动
        t1.setPriority(10);
        t2.setPriority(1);
        t2.start();
        t1.start();
        System.out.println(Thread.currentThread().getName()+"的优先级是"+Thread.currentThread().getPriority());
    }
}

